package cn.wsn2018.tools.runner;

import cn.wsn2018.tools.dao.SystemConfigDao;
import cn.wsn2018.tools.dao.impl.SystemConfigImpl;
import cn.wsn2018.tools.model.RsaObj;
import cn.wsn2018.tools.util.rsa.RSAUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @program: tools
 * @description
 * @author: songDaisong
 * @create: 2020-01-14 19:42
 **/
@Component
public class StartServiceRunner implements ApplicationRunner {

    //项目启动自动初始化系统参数配置表

    @Autowired
    SystemConfigDao systemConfigDao;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        systemConfigDao.initialSystemConfig();

        //生成rsa密钥对
        Map<String, Object> genKeyPair = RSAUtils.genKeyPair();
        String publicKey = RSAUtils.getPublicKey(genKeyPair);
        String privateKey = RSAUtils.getPrivateKey(genKeyPair);
        //设置rsa算法的公钥私钥
        RsaObj rsaObj = RsaObj.getInstance();
        rsaObj.setPublickKey(publicKey);
        rsaObj.setPrivateKey(privateKey);

    }
}
